<?php
/**
 * cms后台文章修改管理页
 * author wang
 * mail:970633164@qq.com
 */

define("PHP_IN",true);
require "../include/init.php";
require "checklogin.php";
require ROOT_PATH."cms/smart_connection.php";

$page = isset($_GET['page']) ? $_GET['page'] : 1;
$adminid = isset($_GET['adminid'])? $_GET['adminid']:0;
$password = isset($_GET['password'])? $_GET['password']:$_SESSION['password'];

if(isset($_POST['dosubmit'])){
    $password = trim($_POST['password']);
    $password_old = trim($_POST['password_old']);
    $password_new1 = trim($_POST['password_new1']);
    $password_new2 = trim($_POST['password_new2']);

    if($password=="" || $password_new1=="" || $password_new2==""){
        alert("请填写完整信息！");
    }

    if(md5($password_old) != $password){
        alert("密码错误，请重新输入");
        exit;
    }
    if($password_new1 != $password_new2){
        alert("两次密码不一致，请重新输入");
        exit;
    }

    $password_md5 = md5($password_new1);

    $adminid = $_POST['adminid'];
    $sql = "UPDATE admin SET password='$password_md5' WHERE adminid = '$adminid'";
    $result = $db->query($sql);
    if ($result) {
        alert("修改成功", "admin_list.php?page=".$page);
    } else {
        alert("修改失败");
    }
}

$smarty->assign("password",$password);
$smarty->assign("page",$page);
$smarty->assign("adminid",$adminid);

$smarty->display("admin_edit.tpl");
$db->close();
?>